<?php
class Budget_cycle_model extends CI_Model {
	
	private $tbl_data= 'MST_BUDGET_CYCLE';
	public function __construct()
	{
		parent::__construct();
	}
	
	function list_all($fccode){
		//$this->db->order_by('id','asc');
		return "SELECT A.ID,B.FCNAME,A.BGYEAR+543 BGYEAR,A.START_DATE,A.END_DATE FROM MST_BUDGET_CYCLE A INNER JOIN DTS_CORPORATE B ON A.FCCODE=B.FCCODE WHERE A.FCCODE='$fccode'";
	}
		
	function count_all(){
		return $this->db->count_all($this->tbl_data);
	}
 
	function get_by_id($id){
		$this->db->where('ID', $id);
		return $this->db->get($this->tbl_data)->row();
	 
	}
	function get_by_year($corporate,$year){
		//$this->db->where('ID', $id);
		$sql="SELECT ID,FCCODE,BGYEAR,START_DATE,END_DATE ,CONVERT(VARCHAR(10),START_DATE,110) P_START,CONVERT(VARCHAR(10),END_DATE,110) P_END
			FROM dbo.MST_BUDGET_CYCLE WHERE FCCODE='$corporate' AND BGYEAR=$year";
		return $this->db->query($sql)->row();
	 
	}		
	function get_by_corp($fccode){
		$this->db->where('FCCODE', $fccode);
		return $this->db->get($this->tbl_data)->result_array();
	}	
	function save($item){		
		$this->db->insert($this->tbl_data, $item);	
		return $this->db->insert_id();	
	}
	
	function update($item,$id){
		$this->db->where('ID', $id);
		$this->db->update($this->tbl_data, $item);
	}
	
	function delete($id){
		$this->db->where('ID', $id);
		$this->db->delete($this->tbl_data);
	}
}
?>